package com.songlanyun.modules.celebrity.controller.admin;

import com.songlanyun.common.annotation.RepeatSubmit;
import com.songlanyun.common.annotation.SysLog;
import com.songlanyun.common.enums.PrivateMessageConstant;
import com.songlanyun.common.enums.SysConstant;
import com.songlanyun.common.utils.PageUtils;
import com.songlanyun.common.utils.R;
import com.songlanyun.modules.celebrity.entity.UserApplyNetRed;
import com.songlanyun.modules.celebrity.model.UserApplyNetRedCheckDTO;
import com.songlanyun.modules.celebrity.service.UserApplyNetRedService;
import com.songlanyun.modules.message.model.to.MessageTO;
import com.songlanyun.modules.message.service.SendPrivateMessageMsgService;
import com.songlanyun.modules.user.controller.AbstractController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


/**
 * 网红申请 Admin
 *
 * @author zx
 * @date 2021年3月1日 11:42:07
 */
@RestController
@RequestMapping("admin/celebrity")
public class UserApplyNetRedAdminController extends AbstractController {

    @Autowired
    private UserApplyNetRedService userApplyNetRedService;

    @Autowired
    private SendPrivateMessageMsgService sendPrivateMessageMsgService;

    /**
     * 分页列表
     */
    @GetMapping("/page")
    public R page(@RequestParam Map<String, Object> params) {
        PageUtils page = userApplyNetRedService.queryPage(params);
        return R.ok().put("page", page);
    }

    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Long id) {
        return R.ok().put("data", userApplyNetRedService.queryOneById(id));
    }

    /**
     * 网红申请
     * 审核
     */
    @SysLog("网红申请审核")
    @RepeatSubmit(value = "3")
    @PutMapping("/check")
    public R check(@RequestBody UserApplyNetRedCheckDTO dto){
        verifyAdmin();//校验用户

        UserApplyNetRed check = userApplyNetRedService.check(dto);

        //发送互动消息
        sendPrivateMessageMsgService.send(new MessageTO(PrivateMessageConstant.MessageType.INTERACTION_MESSAGE,
                PrivateMessageConstant.ModelType.CHECK, check.getId(),
                SysConstant.InteractionType.NETRED_CHECK, check.getUserId()));
        return R.ok().put("data", check);
    }

    /**
     * 删除
     */
//    @SysLog("删除 网红申请")
//    @RepeatSubmit(value = "3")
//    @DeleteMapping("/deleteById/{id}")
//    public R deleteById(@PathVariable("id") Long id) {
//        verifyAdmin();//校验用户
//        return R.ok().put("data", userApplyNetRedService.removeById(id));
//    }

}
